﻿using KZ.Express.ENT;
using KZ.Express.Presenter;
using KZ.Express.Resource;
using KZ.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KZ.Express.Order.Log
{
    public partial class LogListView : FormBase
    {
        #region Private Variables


        #endregion

        #region Private Methods
        
        private void LogListView_Load(object sender, EventArgs e)
        {
            dtpFrom.Value = DateTime.Today.GetFirstDayOfMonth();
            dtpTo.Value = DateTime.Today.GetLastDayOfMonth();
            base.LoadData();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            base.LoadData();
        }

        private void dtgLog_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            MainView view = Application.OpenForms["MainView"] as MainView;
            view.HandleAction(ActionName.View);
        }

        #endregion

        #region Constructors
        
        public LogListView()
        {
            InitializeComponent();
            base.ObjectID = (int)Objects.Logs;

            base.OrderBy = "Date";
            base.OrderDirection = "DESC";

            base.Action = ActionName.List;
            base.InitializeDataGrid(dtgLog);
            base._presenter = new PresenterBase(this, new LogENT());

            dtgLog.ColumnHeaderMouseClick += dtg_ColumnHeaderMouseClick;

            Global.SetDoubleBuffered(dtgLog);
        } 

        #endregion

        #region Public Properties

        [Search]
        public DateTime From
        {
            get { return dtpFrom.Value; }
            set
            {
                if (value != DateTime.MinValue)
                    dtpFrom.Value = value;
            }
        }

        [Search]
        public DateTime To
        {
            get { return dtpTo.Value; }
            set
            {
                if (value != DateTime.MinValue)
                    dtpTo.Value = value;
            }
        }

        #endregion
    }
}
